<template>
    <div class="box">
        <header class="header">
            <van-nav-bar title="收货地址" left-arrow @click-left="$router.back()" />
        </header>
        <div class="content">
            <van-address-list v-model="chosenAddressId" :list="addressList" @add="onAdd" @edit="onEdit"
                @select="onSelect" />
        </div>
    </div>
</template>
<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
export default {
    data() {
        return {
            chosenAddressId: '',
        }
    },
    created() {
        this.chosenAddressId = this.checkedAddress.id
    },
    computed: {
        ...mapState(['addressList']),
        ...mapGetters(['checkedAddress'])
    },
    methods: {
        ...mapMutations(['changeisChecked']),
        onSelect(item) {
            console.log(item, 'item')
            this.changeisChecked(item.id)// 选中张三这一条 应该是张三这条数据的isChecked为true,其他的都改为false
            this.$router.go(-1)//  跳转到上一页
        },
        onAdd() {
            this.$router.push('/order/add')
        },
        onEdit(item) {
            this.$router.push(`/order/edit/${item.id}`)
        }
    }
}
</script>